﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Portal.Web.Model;
using Portal.Cms.Model;
using Portal.Cms.Bussiness;
using Portal.Web.Utility;
using Portal.Core;
using Portal.Cms.Utility;

namespace Portal.Cms.Render
{
    public class GroupDataRenderBll
    {
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string DataTypeId = (string)WebEnvironments.Request(SiteId, "DataType");
                DataTypeCls[] DataTypes = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingDataType(SiteId);
                string SelectDataType = "<select id=drpSelectDataType class=CssSelectDataType>\r\n";
                for (int iIndex = 0; iIndex < DataTypes.Length; iIndex++)
                {
                    SelectDataType += "   <option value=\"" + DataTypes[iIndex].DataTypeId + "\">" + DataTypes[iIndex].DataTypeName + "</option>\r\n";
                }
                SelectDataType += "</select>\r\n";
                string Html =
                   "<script language=javascript>\r\n" +
                   "    function ClientPublic(CmsGroupDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn phát hành chưa?')==false)return;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSidePublic(SiteId,CmsGroupDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +

                   "        document.getElementById('divStatusText'+CmsGroupDataId).innerHTML = AjaxOut.InfoMessage;\r\n" +
                   "        document.getElementById('divButton'+CmsGroupDataId).innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientUnPublic(CmsGroupDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn ngưng phát hành chưa?')==false)return;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSideUnPublic(SiteId,CmsGroupDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divStatusText'+CmsGroupDataId).innerHTML = AjaxOut.InfoMessage;\r\n" +
                   "        document.getElementById('divButton'+CmsGroupDataId).innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientAdd(DataType)\r\n" +
                   "    {\r\n" +
                   "        SiteId='"+SiteId+"';\r\n"+
                   "        document.getElementById('divActionForm').style.display='block';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.DrawAddForm(SiteId, DataType).value;\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        document.getElementById('txtSubject').focus();\r\n"+
                   "    }\r\n" +

                   "    function ClientUpdate(DataType,GroupDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        document.getElementById('divActionForm').style.display='block';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.DrawUpdateForm(SiteId, DataType, GroupDataId).value;\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        document.getElementById('txtSubject').focus();\r\n" +
                   "    }\r\n" +

                   "    function ClientInputData(DataType,GroupDataId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(DataType=='document')\r\n"+
                   "        {\r\n"+
                   "            window.open('DocumentMan/Home.aspx?gid='+GroupDataId,'_self');\r\n" +
                   "        }\r\n"+
                   "        else\r\n"+
                   "        {\r\n"+
                   "            window.open('InputData.aspx?gid='+GroupDataId,'_self');\r\n"+
                   "        }\r\n"+
                   "    }\r\n" +


                   "    function ClientBack()\r\n" +
                   "    {\r\n" +
                   "        document.getElementById('divActionForm').style.display='none';\r\n" +
                   "        document.getElementById('divListForm').style.display='block';\r\n" +
                   "    }\r\n" +

                   "    function ClientAddGroupData(DataType)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        Alias= document.getElementById('txtAlias').value;\r\n" +
                   "        LinkAlias = '';\r\n"+//document.getElementById('txtLinkDataAlias').value;\r\n" +
                   "        subject = document.getElementById('txtSubject').value;\r\n" +
                   "        description = document.getElementById('txtDescription').value;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSideAdd(SiteId,DataType, Alias, LinkAlias, subject, description).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n"+
                   "        {\r\n"+
                   "            alert(AjaxOut.InfoMessage);\r\n"+
                   "            return;\r\n"+
                   "        }\r\n"+
                   "        document.getElementById('divActionForm').innerHTML = '';\r\n" +
                   "        document.getElementById('divActionForm').style.display = 'none';\r\n" +
                   "        document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        ClientBack();\r\n"+
                   "    }\r\n" +


                   "    function ClientDelete(DataType,GroupDataId)\r\n"+
                   "    {\r\n"+
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n"+
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSideDelete(SiteId,DataType, GroupDataId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n"+

                   "    function ClientSaveGroupData(DataType,GroupDataId)\r\n" +
                   "    {\r\n"+
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        Alias= document.getElementById('txtAlias').value;\r\n" +
                   "        LinkAlias= '';\r\n"+//document.getElementById('txtLinkDataAlias').value;\r\n" +
                   "        subject = document.getElementById('txtSubject').value;\r\n" +
                   "        description = document.getElementById('txtDescription').value;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSideSave(SiteId,DataType, GroupDataId, Alias, LinkAlias, subject, description).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = '';\r\n" +
                   "        document.getElementById('divActionForm').style.display = 'none';\r\n" +
                   "        document.getElementById('divListForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        ClientBack();\r\n" +
                   "    }\r\n"+

                   "    function SearchData()\r\n"+
                   "    {\r\n"+
                   "        document.getElementById('divSeachDataForm').style.display='block';\r\n"+
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "    }\r\n"+

                   "    function ClientBackFromSearchForm()\r\n"+
                   "    {\r\n"+
                   "        document.getElementById('divSeachDataForm').style.display='none';\r\n" +
                   "        document.getElementById('divListForm').style.display='block';\r\n" +
                   "    }\r\n"+

                   "    function ClientExecuteSearchData()\r\n"+
                   "    {\r\n"+
                   "        SiteId='"+SiteId+"';\r\n"+
                   "        DataType = document.getElementById('drpSelectDataType').value;\r\n"+
                   "        SearchSubject = document.getElementById('txtSearchSubject').value;\r\n"+
                   "        SearchDescription = document.getElementById('txtSearchDescription').value;\r\n" +
                   "        AjaxOut = Portal.Cms.Render.GroupDataRenderBll.ServerSideSearchData(SiteId,DataType, SearchSubject, SearchDescription).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divSearchResult').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n"+
                   "</script>\r\n" +
                   "<div id=divSeachDataForm style=\"display:none\">\r\n"+
                     "  <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientExecuteSearchData();\"><img class=image src=\"Resources/Images/Save.png\"><div>Ghi lại</div></li>\r\n" +
                    "            <li onclick=\"javascript:ClientBackFromSearchForm();\"><img class=image src=\"Resources/Images/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +
                    "   <h3>Tìm kiếm dữ liệu để liên kết</h3>\r\n" +
                    "   <div class=SearchForm>"+
                    "       <table>\r\n"+
                    "           <tr>\r\n"+
                    "               <td class=c1>Loại dữ liệu:</td>\r\n"+
                    "               <td class=c2>" + SelectDataType + "</td>\r\n" +
                    "           </tr>\r\n"+
                    "           <tr>\r\n"+
                    "               <td class=c1>Tiêu đề:</td>\r\n"+
                    "               <td class=c2><input id=\"txtSearchSubject\" type=textbox class=textbox></td>\r\n" +
                    "           </tr>\r\n"+
                    "           <tr>\r\n" +
                    "               <td class=c1>Mô tả:</td>\r\n" +
                    "               <td class=c2><input id=\"txtSearchDescription\" type=textbox class=textbox></td>\r\n" +
                    "           </tr>\r\n" +
                    //"           <tr>\r\n" +
                    //"               <td class=c1></td>\r\n" +
                    //"               <td class=c2><input type=button class=button value=\"Tìm kiếm\" onclick=\"javascript:ClientExecuteSearchData();\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBackFromSearchForm();\"></td>\r\n" +
                    //"           </tr>\r\n" +
                    "       </table>\r\n"+
                    "   </div>\r\n"+
                    "   <div class=CssSearchResult id=divSearchResult></div>\r\n"+
                   "</div>\r\n"+
                    "<div id=divActionForm class=CssActionForm></div>\r\n" +
                   "<div id=divListForm class=tabcontent>\r\n" +
                        ServerSideReading(SiteId,DataTypeId).HtmlContent+
                   "</div>\r\n";
                   
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReading(string SiteId, string DataType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonIconUrl = WebConfig.GetButtonIconRoot(OSiteParam);
                DataTypeCls ODataType = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateDataTypeModel(SiteId, DataType);
                if (ODataType == null) throw new Exception("Không tìm thấy kiểu dữ liệu này! Truy cập không hợp lệ!");
                GroupDataCls[] GroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingGroupData(SiteId, DataType);
                string Back = "Home.aspx";
                string Html =
                     "  <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientAdd('"+ODataType.DataTypeId+"');\"><img class=image src=\""+ButtonIconUrl+"/Add.png\"><div>Thêm mới</div></li>\r\n" +
                    "            <li onclick=\"javascript:window.open('" + Back + "','_self');\"><img class=image src=\""+ButtonIconUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +

                   "        <h3>" + ODataType.DataTypeName + " - " + GroupData.Length + "</h3>\r\n" +
                   "            <table>\r\n" +
                   "                <tr>\r\n" +
                   "                    <th>#</th>\r\n" +
                   "                    <th>Mã</th>\r\n" +
                   //"                    <th>Liên kết</th>\r\n" +
                   "                    <th>Tiêu đề</th>\r\n" +
                   "                    <th>Mô tả</th>\r\n" +
                   "                    <th>Ngày tạo</th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                </tr>\r\n";
                for (int iIndex = 0; iIndex < GroupData.Length; iIndex++)
                {
                    string ReleaseButton =
                       "<input type=button class=button value=\"Phát hành\" onclick=\"javascript:ClientPublic('" + GroupData[iIndex].GroupDataId + "');\">";
                    if (GroupData[iIndex].ActiveGroupData == 1)
                    {
                        ReleaseButton =
                            "<input type=button class=button value=\"Ngưng phát hành\" onclick=\"javascript:ClientUnPublic('" + GroupData[iIndex].GroupDataId + "');\">";
                    }


                    string ConfigData = "";
                    //if (ODataType.AllowDocumentType==1)
                    //{
                    //    ConfigData = "<input type=button class=button value=\"Cấu hình\" onclick=\"javascript:window.open('DocumentConfig.aspx?gid="+GroupData[iIndex].GroupDataId+"','_self');\">";
                    //}
                    if (ODataType.DataTypeId.Equals("vote"))
                    {
                        ConfigData = "<input type=button class=button value=\"Thống kê\" onclick=\"javascript:window.open('ViewStatitics.aspx?gid=" + GroupData[iIndex].GroupDataId + "','_self');\">";
                        //nfigData = "<input type=button class=button value=\"Thống kê\" onclick=\"javascript:alert('Đang xây dựng chức năng thống kê!');\">";
                    }
                    //if (ODataType.DataTypeId.Equals("news"))
                    //{
                    //    InputData = "";
                    //}
                    Html +=
                       "                <tr>\r\n" +
                       "                    <td>" + (iIndex + 1) + "</td>\r\n" +
                       "                    <td>" + GroupData[iIndex].Alias + "</td>\r\n" +
                       //"                    <td>" + LinkText + "</td>\r\n" +
                       "                    <td>" + GroupData[iIndex].GroupDataName + "</td>\r\n" +
                       "                    <td>" + GroupData[iIndex].GroupDataDescription + "</td>\r\n" +
                       "                    <td style=\"width:120px;\">" + GroupData[iIndex].EntryDate.ToString("dd/MM/yyyy HH:mm") + "</td>\r\n" +
                       "                    <td><div id=\"divStatusText" + GroupData[iIndex].GroupDataId + "\">" + (GroupData[iIndex].ActiveGroupData == 1 ? "Đã phát hành" : "Chờ phát hành") + "</div><div id=\"divButton" + GroupData[iIndex].GroupDataId + "\">" + ReleaseButton + "</div></td>\r\n" +
                       "                    <td style=\"width:10px;\"><input type=button class=button value=\"Sửa\" onclick=\"javascript:ClientUpdate('" +DataType+"','"+ GroupData[iIndex].GroupDataId + "');\"></td>\r\n" +
                       "                    <td style=\"width:10px;\"><input type=button class=button value=\"Xóa\" onclick=\"javascript:ClientDelete('"+DataType+"','"+ GroupData[iIndex].GroupDataId+"');\"></td>\r\n" +
                       "                    <td style=\"width:10px;\">"+ConfigData+"</td>\r\n" +
                       "                </tr>\r\n";
                }
                Html +=
                   "    </table>\r\n";
                   
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawAddForm(string SiteId, string DataType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonIconUrl = WebConfig.GetButtonIconRoot(OSiteParam);
            
                string Html =
                    "  <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientAddGroupData('" + DataType + "');\"><img class=image src=\""+ButtonIconUrl+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
                    "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\""+ButtonIconUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +

                   "  <h3>Thêm mới nhóm dữ liệu</h3>\r\n" +
                   "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1>Mã:</td>\r\n" +
                   "        <td class=c2><input id=txtAlias value=\""+System.Guid.NewGuid().ToString().Substring(0,8)+"\" class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1></td>\r\n" +
                   "        <td class=c2>(*) Chú ý: Mã không được viết cách và không viết tiếng Việt</td>\r\n" +
                   "    </tr>\r\n" +
                   //"    <tr>\r\n" +
                   //"        <td class=c1>Mã liên kết:</td>\r\n" +
                   //"        <td class=c2><input id=txtLinkDataAlias value=\"\" class=textbox type=textbox></td>\r\n" +
                   //"    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1>Tiêu đề:</td>\r\n"+
                   "        <td class=c2><input id=txtSubject class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n"+
                   "    <tr>\r\n" +
                   "        <td class=c1>Mô tả:</td>\r\n" +
                   "        <td class=c2><input id=txtDescription class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   //"    <tr>\r\n" +
                   //"        <td class=c1></td>\r\n" +
                   //"        <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:ClientAddGroupData('"+DataType+"');\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBack();\"></td>\r\n" +
                   //"    </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawUpdateForm(string SiteId, string DataType,string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonIconUrl = WebConfig.GetButtonIconRoot(OSiteParam);

                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                string Html =
                     "  <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:ClientSaveGroupData('" + DataType + "','"+GroupDataId+"');\"><img class=image src=\""+ButtonIconUrl+"/Save.png\"><div>Ghi lại</div></li>\r\n" +
                    "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\""+ButtonIconUrl+"/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +
                   "  <h3>Sửa nhóm dữ liệu</h3>\r\n" +
                   "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1>Mã:</td>\r\n" +
                   "        <td class=c2><input id=txtAlias class=textbox type=textbox value=\"" + OGroupData.Alias + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1></td>\r\n" +
                   "        <td class=c2>(*) Chú ý: Mã không được viết cách và không viết tiếng Việt</td>\r\n" +
                   "    </tr>\r\n" +
                   //"    <tr>\r\n" +
                   //"        <td class=c1>Liên kết:</td>\r\n" +
                   //"        <td class=c2><input id=txtLinkDataAlias class=textbox type=textbox value=\"" + OGroupData.LinkDataAlias + "\"></td>\r\n" +
                   //"    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1>Tiêu đề:</td>\r\n" +
                   "        <td class=c2><input id=txtSubject class=textbox type=textbox value=\"" + OGroupData.GroupDataName + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=c1>Mô tả:</td>\r\n" +
                   "        <td class=c2><input id=txtDescription class=textbox type=textbox value=\"" + OGroupData.GroupDataDescription + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   //"    <tr>\r\n" +
                   //"        <td class=c1></td>\r\n" +
                   //"        <td class=c2><input type=button class=button value=\"Chấp nhận\" onclick=\"javascript:ClientSaveGroupData('" + DataType + "','"+GroupDataId+"');\"><input type=button class=button value=\"Quay lại\" onclick=\"javascript:ClientBack();\"></td>\r\n" +
                   //"    </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAdd(string SiteId, string DataType, string Alias, string LinkAlias, string Subject,string Description)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                if (string.IsNullOrEmpty(Subject)) throw new Exception("Chưa nhập tiêu đề nhóm dữ liệu!");

                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).AddGroupData(SiteId, DataType, Alias, LinkAlias, Subject, Description);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId, DataType).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideSave(string SiteId, string DataType, string GroupDataId, string Alias, string LinkAlias, string Subject, string Description)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                if (string.IsNullOrEmpty(Subject)) throw new Exception("Chưa nhập tiêu đề nhóm dữ liệu!");
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).SaveGroupData(SiteId, DataType, GroupDataId, Alias, LinkAlias, Subject, Description);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId, DataType).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDelete(string SiteId, string DataType,string GroupDataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).DeleteGroupData(SiteId, GroupDataId);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId, DataType).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideSearchData(string SiteId, string DataType, string Subject,string Description)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsDataCls[] CmsDatas = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).SearchCmsData(SiteId, DataType, Subject, Description);
                string Html = "<table>\r\n" +
                              " <tr>\r\n" +
                              "   <th class=thIndex>#</th>\r\n" +
                              "   <th class=thSubject>Tiêu đề</th>\r\n" +
                              "   <th class=thStatus>Trạng thái</th>\r\n" +
                              "   <th class=thFunc></th>\r\n" +
                              " </tr>\r\n";
                for (int iIndex = 0; iIndex < CmsDatas.Length; iIndex++)
                {
                    Html +=   " <tr>\r\n" +
                              "   <td>"+(iIndex+1)+"</td>\r\n" +
                              "   <td>" + CmsDatas[iIndex].Subject + "<div class=CssItemDesc>" + CmsDatas[iIndex].Description + "</div></td>\r\n" +
                              "   <td>" + (CmsDatas[iIndex].IsPublic==1?"Đã phát hành":"Chờ phát hành") + "</td>\r\n" +
                              "   <td><input type=button class=button value=\"Chọn dữ liệu này\"></td>\r\n" +
                              " </tr>\r\n";
                }
                Html += "</table>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSidePublic(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).PublicGroupData(SiteId, DataId);

                OAjaxOut.HtmlContent =
                    "<input type=button class=button  value=\"Ngưng phát hành\" onclick=\"javascript:ClientUnPublic('" + DataId + "');\">";
                OAjaxOut.InfoMessage = "Đã phát hành";
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideUnPublic(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).UnPublicGroupData(SiteId, DataId);

                OAjaxOut.HtmlContent =
                    "<input type=button class=button value=\"Phát hành\" onclick=\"javascript:ClientPublic('" + DataId + "');\">";
                OAjaxOut.InfoMessage = "Chưa phát hành";
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
                OAjaxOut.Error = true;
            }

            return OAjaxOut;
        }
    }
}
